<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>欢迎注册Online Judge</title>
    <link rel="stylesheet" type="text/css" href="<%=basePath %>css/font-awesome-4.3.0/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath %>css/regist_style.css"/>
    <link rel="stylesheet" type="text/css" href="<%=basePath %>css/button.css">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="<%=basePath %>js/jquery-1.7.1.min.js"></script>
	<script type="text/javascript" src="<%=basePath %>js/jquery.json-2.4.min.js"></script>

  
  <script type="text/javascript">
  var flag ;
  
  $(function (){
	  $("#registform").validate();
  })
  
  function check_username(){
		$("#reg_username_text").text("");
		var username = $("#reg_username").val();
		$.get("./UserAction!userexit.action", {name:username}, callback);
	}
  
  function callback(data){
	  
	  var arr = new Array();
	  arr = data.split("%");
	  if(arr[0]==1){
		  $("#reg_username_text").text(arr[1]);
		  flag = true;
	  }
	  else{
		  $("#reg_username_text").text(arr[1]);
		  flag = false;
	  }
  }
  
  function check_psw(){

	  
	var password = $.trim($("#reg_userpassword").val());
	  if(password.length == 0){
	  	$("#reg_userpassword_text").text('密码不能空');

	  	return false;
	  }
	  else{
	  	$("#reg_userpassword_text").text('');
	
	  	return true;
	  }
	}
  
  function again_psw(){
	  var password =  $.trim($("#reg_userpassword").val());
	  var password1 =  $.trim($("#again_userpassword").val());
	  if(password == password1){
	  $("#agi_userpassword_text").text('');

		  	return true;
	  }
	  else{
		  $("#agi_userpassword_text").text('请输入正确的密码');
	
		  	return false;
	  }
	  
	  
  }
  
  function check_tel(){
	  var tel =  $.trim($("#tel").val());
	  if(tel == null || tel.length == 0){
	  	$("#tel_text").text('联系方式不能为空！');
	
	  	return false;
	  }else{
	  	   var pattern= /^1[1-9][0-9]\d{4,8}$/;
	  	   if(pattern.test(tel)){
	  	   	   $("#tel_text").text('');
	  		 
	  		 return true;
	  	   } else {
	  	       $("#tel_text").text('请填写正确的号码！');
	  	       $("#tel_text");
	  		 
	  		 return false;
	  	 }	
	  	
	  	}   
	  }
  
  function check_stuid(){
		var str =  $.trim($("#stuid").val());
		slen=str.length;
		if(slen==0) {
			$("#stuid_text").text('');
				$("#stuid_text").text('电话不能为空！');
				
				return false;
			}
		for (i=0; i<slen; i++){
		  cc = str.charAt(i);
		  if (cc <"0" || cc >"9"){
		  	$("#stuid_text").text('只能填入数字！');
		
		   return false;
		  }
		  else{
		  	$("#stuid_text").text('');
		 
		  	return true;
		  	}
		}
	}
  
  function check_college(){
	  var college =  $.trim($("#college").val());
	  if(college == null || college.length == 0){
	  	$("#college_text").text('所在学院不能为空！');
	
	  	return false;
	  }
	  else{
	  	$("#college_text").text('');
	 
	  	return true;
	  }
	  }
  
  function do_regist(){
  	if(flag){
  		alert("用户名已存在！");
  		return;
  	}
	   flag1 = check_psw() ;	 
	   flag2 = again_psw();
	   flag3 = check_tel() ;  
	   flag4 = check_stuid() ;
	   flag5 = check_college();
	  if(flag1&&flag2&&flag3&&flag4&&flag5){
	  	document.getElementById("registform").submit();
	  }
	  else
		  alert("请将信息填写完整");
  }
  
  function back(){
	  window.location.href="<%=request.getContextPath() %>";
  }
  
  </script>

  </head>
  <body>
  <header class="top">
  	<img src="./images/logo.gif" style="margin: 4px 0 0 10px;width: 200px;height: 57px;"></img>
  </header>
    <form id="registform" action="./UserAction!adduser.action" method="post" ">
    <div class="center"> 
    	<div class="title">
    		<h1>欢迎注册Online Judge</h1>
    		<p onclick="back()">&lt;&lt;返回主页</p> 
    	</div>
    	<div class="main_form">
			<span style="display: inline-block;width: 120px;margin-top:35px">用户名</span><input id="reg_username" name="user.username"  type="text" onblur="check_username()" ><span class="xspan" style="margin:34px 0 0 14px">*</span></span></br>
			<span style="display: inline-block;width: 120px;">密　码</span><input id="reg_userpassword" name="user.userpassword"  type="password" onblur="check_psw()"  ><span class="xspan">*</span></span></br>
			<span style="display: inline-block;width: 120px;">确认密码</span><input id="again_userpassword" name="againpassword"  type="password" onblur="again_psw()"  ><span class="xspan">*</span></span></br>
			<span style="display: inline-block;width: 120px;">真实姓名</span><input id="reg_realname" name="user.realname"  type="text"  ><span class="xspan">*</span></span></br>
			<span style="display: inline-block;width: 120px;">联系方式</span><input id="tel"  type="text" name="user.tel"><span id="stuid_text"  >*</span></br>
			<span style="display: inline-block;width: 120px;">学　号</span><input id="stuid"  type="text" name="user.stunum" /><span id="stuid_text"  >*</span></br>
			<span style="display: inline-block;width: 120px;">学　院</span><input id="college"  type="text" name="user.college"  onblur="check_college()"/><span id="college_text" class="std_college">*</span></br>
		</div>
	<div class="bottom">
		<input type="Button"  value="提交" class="reg_btn" onclick="do_regist()"/>
		<p>已经注册了？直接<b><a href="login.jsp">登录</a></b></p>
	</div>
	</div>
</form>
</div>

  </body>
</html>
